package com.xinhe.cn.cpbox.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinhe.cn.cpbox.entity.po.MatchMaker;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xinhe.cn.cpbox.entity.po.ScripSend;
import com.xinhe.cn.cpbox.entity.po.UserInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * <p>
 * 月老信息 Mapper 接口
 * </p>
 *
 * @author LHB
 * @since 2021-10-09
 */
@Repository
public interface MatchMakerMapper extends BaseMapper<MatchMaker> {

    @Select("select img_url, nick_name, uid from match_maker mm left join user_info ui on mm.match_maker_id=ui.open_id ${ew.customSqlSegment}")
    IPage<UserInfo> selectMakerByParent(Page<UserInfo> mpPage, @Param(Constants.WRAPPER) QueryWrapper queryWrapper);

    @Update("update match_maker set user_num=user_num+#{num} where match_maker_id=#{extendId}")
    void addUserNum(@Param("extendId") String extendId, @Param("num") int num);

    @Update("update match_maker set child_num=child_num+#{num} where match_maker_id=#{extendId}")
    void addChildNum(@Param("extendId") String extendId, @Param("num") int num);

    @Update("update match_maker set grandchild_num=grandchild_num+#{num} where match_maker_id=#{extendId}")
    void addGrandchildNum(@Param("extendId") String extendId, @Param("num") int num);

    @Update("update match_maker set total_money=total_money+#{addMoney}, left_money=left_money+#{addMoney} where match_maker_id=#{matchMakerId} ")
    void addMoney(@Param("addMoney") String addMoney, @Param("matchMakerId") String matchMakerId);

    @Update("update match_maker set left_money=left_money-#{minusMoney}, has_apply=0 where match_maker_id=#{matchMakerId} ")
    void completeMoneyApply(@Param("minusMoney") String minusMoney, @Param("matchMakerId") String matchMakerId);
}
